<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!DOCTYPE html>
<html xmlns:th="" lang="zh-CN">
<%@include file="/WEB-INF/pages/base/include.jsp"%>
<body>
<div id="wrapper">
    <%@include file="/WEB-INF/pages/base/menu.jsp"%>
    <div id="page-wrapper">
        <div class="row">
            <div class="col-lg-12">
                <h3 class="page-header">奖励机制管理</h3>
            </div>
        </div>
        <div class="row">
            <form class="form-horizontal" data-parsley-validate>
                <div class="col-lg-12 col-md-12">
                    <div class="panel panel-default">
                        <div class="panel-heading">奖励机制基本信息</div>
                        <div class="panel-body">
                            <div class="row">
                                <div class="col-lg-12 col-md-12">
                                	<div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">满足的数量：</label>
                                        <div class="col-lg-8">
                                            <input type="text" id="conditionCount" class="form-control" placeholder="请输入满足的数量"
                                                   required>
                                        </div>
                                        <div class="col-lg-2 clo-md-2">
                                            <span class="help-block">*必须填写</span>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">满足的金额：</label>
                                        <div class="col-lg-8">
                                            <input type="text" id="conditionPrice" class="form-control" placeholder="请输入满足的金额"
                                                   required>
                                        </div>
                                        <div class="col-lg-2 clo-md-2">
                                            <span class="help-block">*必须填写</span>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">奖励内容：</label>
                                        <div class="col-lg-8">
                                            <input type="text" id="incentiveContent" class="form-control" placeholder="请输入奖励内容"
                                                   required>
                                        </div>
                                        <div class="col-lg-2 clo-md-2">
                                            <span class="help-block">*必须填写</span>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">顺序：</label>
                                        <div class="col-lg-8">
                                            <input type="text" id="orderNumber" class="form-control" placeholder="请输入顺序"
                                                   required>
                                        </div>
                                        <div class="col-lg-2 clo-md-2">
                                            <span class="help-block">*必须填写</span>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="clearfix"></div>
                <button type="button" class="btn btn-primary" onclick="cashRed_modify()"
                        style="margin-left:15px;margin-bottom:30px;">发布
                </button>
                <button class="btn btn-default" id="cancel" style="margin-left:15px;margin-bottom:30px;">
                    取消
                </button>
            </form>
        </div>
    </div>
</div>
<script>
	$(function(){
		var incentiveSystemId = "${incentiveSystemId}";
		var baseURL = "${webPath}/incentiveSystem/detail";
	  	var json_package = {
	       "head": {},
	       "body": {
	       	"incentiveSystemId": incentiveSystemId
	       }
	   	}
		$.post(baseURL, {"json_package": JSON.stringify(json_package)}, function (result) {
	      if (typeof result == 'string') result = JSON.parse(result);
	      if (result.body.result == '1') {
	          alert(result.body.description)
	      } else {
	      	var incentiveSystem = result.body.incentiveSystem;
	      	$("#conditionCount").val(incentiveSystem.conditionCount);
	      	$("#conditionPrice").val(incentiveSystem.conditionPrice);
	      	$("#incentiveContent").val(incentiveSystem.incentiveContent);
	      	$("#orderNumber").val(incentiveSystem.orderNumber);
	      }
	  	})
	});
	
	function cashRed_modify() {
    	var baseURL = "${webPath}/incentiveSystem/modify";
    	var incentiveSystemId = "${incentiveSystemId}";
    	var conditionCount = $('#conditionCount').val();
        var conditionPrice = $('#conditionPrice').val();
        var incentiveContent = $('#incentiveContent').val();
        var orderNumber = $('#orderNumber').val();
        
        var json_package = {
       		"head": {},
            "body": {
            	"incentiveSystemId":incentiveSystemId,
            	"conditionCount": conditionCount,
                "conditionPrice": conditionPrice,
                "incentiveContent": incentiveContent,
                "orderNumber": orderNumber
            }
        };
        $.post(baseURL, {"json_package": JSON.stringify(json_package)}, function (result) {
            if (typeof result == 'string') result = JSON.parse(result);
            if (result.body.result == '0') {
                alert('修改成功！')
                window.location.reload(true);
            } else {
                alert('修改失败！')
            }
        })
    }
	$(function () {
        $('#cancel').click(function () {
            window.location.href = "${webPath}toIncentiveSystem";
        })
    });
</script>
</body>
</html>